package cn.nyse.ktc_article.controller;

import cn.nyse.ktc_article.entity.Article;
import cn.nyse.ktc_article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wfw.cn.ktc_common.entity.Result;
import wfw.cn.ktc_common.entity.ResultCode;

@RestController
@CrossOrigin
@RequestMapping("article")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @PostMapping("")
    public Result insertArticle(@RequestBody Article article){
        articleService.save(article);
        return new Result(ResultCode.SUCCESS,null);
    }

    @GetMapping("")
    public Result findAllArticle(){
        return new Result(ResultCode.SUCCESS,articleService.findAllArticle());
    }

    @GetMapping("/{articleId}")
    public Result findByArticle(@PathVariable String articleId){
        return new Result(ResultCode.SUCCESS,articleService.findByArticle(articleId));
    }


}
